package com.opensource.svgaplayer.bitmap;

import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;

/**
 * ex.
 *
 * @author wl
 * @since 2021-06-28
 */
public class SVGABitmapFileDecoder extends SVGABitmapDecoder {
    private static SVGABitmapFileDecoder INSTANCE;
    private ImageSource imageSource;

    /**
     * getInstance
     *
     * @return SVGABitmapFileDecoder
     */
    public static SVGABitmapFileDecoder getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new SVGABitmapFileDecoder();
        }
        return INSTANCE;
    }

    /**
     * onDecode
     *
     * @param data 路径
     * @param ops  配置
     * @return PixelMap
     */
    public PixelMap onDecode(String data, ImageSource.DecodingOptions ops) {
        ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions();
        sourceOptions.formatHint = "image/png";
        imageSource = ImageSource.create(data, sourceOptions);
        return imageSource.createPixelmap(ops);
    }

    /**
     * onDecode
     *
     * @param var1 路径
     * @param var2 配置
     * @return PixelMap
     */
    public PixelMap onDecode(Object var1, ImageSource.DecodingOptions var2) {
        return this.onDecode((String) var1, var2);
    }

    private SVGABitmapFileDecoder() {
    }
}
